﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.VisualStudio.TestTools.Common;
using Microsoft.VisualStudio.TestTools.Common.Xml;
using System.Data;
using System.Diagnostics;

namespace NUnitForVSTS.NUnitTest
{
    /// <summary>
    /// Represents the result of the unittest
    /// </summary>
    [Serializable]
    public class UnitTestResult : TestResultAggregation
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="UnitTestResult"/> class.
        /// </summary>
        /// <param name="result">The result.</param>
        public UnitTestResult(TestResult result): base(result)
        {

        }

        /// <summary>
        /// Initializes a new instance of the <see cref="UnitTestResult"/> class.
        /// </summary>
        /// <param name="computerName">Name of the computer.</param>
        /// <param name="runId">The run id.</param>
        /// <param name="test">The test.</param>
        public UnitTestResult(string computerName, Guid runId, ITestElement test): base(computerName, runId, test)
        {
        }

        /// <summary>
        /// Fills the data row.
        /// </summary>
        /// <param name="row">The row.</param>
        public override void FillDataRow(DataRow row)
        {
            base.FillDataRow(row);
            UnitTestResult result = row["object_column"] as UnitTestResult;
            if ((result == null) || (result.FullyQualifiedClassName != this.FullyQualifiedClassName))
            {
                row["FullyQualifiedClassName"] = this.FullyQualifiedClassName;
            }
            if ((result == null) || (result.ClassName != this.ClassName))
            {
                row["ClassName"] = this.ClassName;
            }
        }

        /// <summary>
        /// Gets the name of the fully qualified class.
        /// </summary>
        /// <value>The name of the fully qualified class.</value>
        public string FullyQualifiedClassName
        {
            get
            {
                UnitTest test = base.Test as UnitTest;
                if (test == null)
                {
                    return string.Empty;
                }
                return test.FullyQualifiedClassName;
            }
        }

        /// <summary>
        /// Gets the name of the class.
        /// </summary>
        /// <value>The name of the class.</value>
        public string ClassName
        {
            get
            {
                UnitTest test = base.Test as UnitTest;
                if (test == null)
                {
                    return string.Empty;
                }
                return test.ClassName;
            }
        }
    }
}
